<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "quiz.Quiz" %>
<%@ page import = "quiz.Question" %>
<% 
	Quiz q = (Quiz)request.getSession().getAttribute("quiz");
	String title = q.getName()+" | Quizzard";
%>
<jsp:include page="templates/header.jsp" flush="true">
	<jsp:param value = "<%= title %>" name = "title" />
</jsp:include>
<jsp:include page="templates/title_bar.jsp" flush = "true">
	<jsp:param value = "<%= q.getName() %>" name = "title" />
</jsp:include>
<div id = "content">
<div class = "center">
<%
	boolean questionNotAnswered = false;
	String success = (String)request.getAttribute("success");
	String error = (String)request.getAttribute("error");
	if (error != null) {
		out.println("<div id = 'error'>"+error+"</div>");
	} else if (success != null) {
		out.println("<div id = 'success'>"+success+"</div>");
	} else {
		request.setAttribute("shouldAllowAnswer", true);
	}
%>
<div class = "section_title dark_bottom_border"><%= q.getDescription() %></div>
<form method = "post" action = "Question">
<%
	request.setAttribute("isInline", "true");
	int i = 1;
	
	for (Question question: q.getQuestions()) {
		request.setAttribute("questionNumber", i);
		request.setAttribute("currentQuestion", question);
%>
	<jsp:include page = "templates/display-question.jsp" />
<%
		i++;
	} 
%>
<input type = "hidden" name = "numQuestions" value = "<%= q.getQuestions().size() %>"/>
<% if (request.getAttribute("shouldAllowAnswer") != null && (Boolean)request.getAttribute("shouldAllowAnswer")) { %>
<input type = "submit" class = "btn" value = "Submit Answers" />
<% } else {  %>
<a href = "Question"><span class = "btn">Continue</span></a>
<% } %>

</form>
</div>
</div>
<jsp:include page="templates/footer.jsp" flush="true" />